// mmap_writer.c
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>

#define SHM_SIZE 4096

int main() {
    int fd = open("/tmp/shmfile", O_CREAT | O_RDWR, 0666);
    ftruncate(fd, SHM_SIZE);

    char *data = (char *)mmap(NULL, SHM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (data == MAP_FAILED) {
        perror("mmap");
        close(fd);
        return 1;
    }

    sprintf(data, "Hello from writer");

    close(fd);
    munmap(data, SHM_SIZE);

    return 0;
}


